﻿using System;
using System.IO;


namespace Hoo.Windows.Shell.Util {
    public static class Logger {


        static string debugFile = getBaseDirectory() + "\\log_debug_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
        static string infoFile = getBaseDirectory() + "\\log_info_" + DateTime.Now.ToString("yyyyMM") + ".txt";
   
        private static void Write(string p, string file, string levelTag) {
            try {

                using (StreamWriter sw = new StreamWriter(file, true)) {
                    string timeMark = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();
                    sw.WriteLine(timeMark + levelTag + p);
                                        
                }
            } catch {
                //
            }
        }

        private static string getBaseDirectory() {
            string dll = System.Reflection.Assembly.GetExecutingAssembly().Location;
            return dll.Substring(0, dll.LastIndexOf('\\'));
        }

        public static void BlankLine() {
            using (StreamWriter sw = new StreamWriter(debugFile, true)) {                
                sw.WriteLine("\n");

            }
        }

        public static void Debug(string p) {
            Write(p, debugFile, " [DEBUG] ");
        }

        public static void Info(String p ) {
            Write(p, debugFile, " [INFO] ");
            Write(p, infoFile, " [INFO] ");
        }

        public static void Warn(String p) {
            Write(p, debugFile, " [WARN] ");
            Write(p, infoFile, " [WARN] ");
        }

        public static void Error(Exception e) {
            string p = e.ToString();
            Write(p, debugFile, " [ERROR] ");
            Write(p, infoFile, " [ERROR] ");
        }


    }

}
